import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $http, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '编号',		name: 'code' },
			{ label: '名称',		name: 'name' },
		],
		// 提交表单列表
		formData : [
			{ label: '名称',		name: 'name', 	 	half:true, required:true },
			{ label: '编号',		name: 'code', 		half:true, required:true, disabled:true },
			{ label: '内容',		name: 'content', 	full:true,      type:'textarea' },
			{ label: '备注',		name: 'remark', 	full:true,		type:'textarea' },
		],
}
	
	model = {}
	
	componentDidMount(){
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'settings/index')
	
	// 表单
	cols = [
		{ title: '编号',		dataIndex: 'code', 		...$fn.table.num },
		{ title: '名称', 	dataIndex: 'name', 		width:150 },
		{ title: '内容', 	dataIndex: 'content', 	width:150 },
		{ title: '备注', 	dataIndex: 'remark', 	width:150 },
		TableControls.controls.call(this)
	]
	// 表格操作按钮
	table_controls = (text,{ id }) =>  [
		TableControls.edit.call(this, 'settings/info', { id },{idStr:'id', nameStr:'id'} ),				// 编辑
	]
	
	render(){
		return (
			<>
				<Page title='系统配置-源配置'>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { idStr:'id' }) }
				</Page>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ editApi:'settings/edit',onComplete:({param})=>{
					 // 开启双录入的时候不显示【快速录入项目】菜单 2022-07-03  --马婷 
					if(param.code === 'P10008'){
						$http.pull(null,'menu/getallmenu',{ param:{ web_version:1 }, loading:false }).then(data=>{
							$fn.remove('menu')
							$fn.local('menu', data)
						})
					}
				} }) }
			</>
		)
	}
}

export default Index